/*!
 * @file       ny8_eeprom.h
 * @brief      EEPROM accessing library
 * @author     HuangTing
 * @date       2021-11-15
 * @details    provide read/write function to access the internal EEPROM.
 *             this header file will include automatically if the EEPROM
 *             is supported by selected ic body.
 * 
 * 2020-03-28 first edition.
 * 2020-08-18 add eeprom_wrtie_timeout for NY8AE51E.
 * 2021-11-15 allow NYIDE define __EEPROM_TIMEOUT=0
 */

#ifndef NY8_EEPROM_H_HQQG1C20
#define NY8_EEPROM_H_HQQG1C20

#ifndef __EEPROM_SUPPORTED
#  error "do NOT include ny8_eeprom.h directly."
#endif

/** read a byte from EEPROM
 *
 * @param[in]  address  EEPROM address
 * @return     8bit value read from EEPROM
 */
unsigned char eeprom_read (unsigned char address);

#if defined(__EEPROM_TIMEOUT) && __EEPROM_TIMEOUT
/** write a byte to EEPROM
 *
 * @param[in] address  EEPROM address
 * @param[in] value    the value that will write to EEPROM
 * @param[in] timeout  enum EEPROM_TIMEOUT
 */
void eeprom_write_timeout (unsigned char address, unsigned char value, unsigned char timeout);
#endif

/** write a byte to EEPROM
 *
 * @param[in] address  EEPROM address
 * @param[in] value    the value that will write to EEPROM
 */
void eeprom_write (unsigned char address, unsigned char value);

/** lock / unlock the write-protection of EEPROM
 */
void eeprom_protect_lock (void);

#define eeprom_protect_unlock() \
        eeprom_protect_lock()

#endif /* end of include guard: NY8_EEPROM_H_HQQG1C20 */
